// pages/top250/top250.js
const {http,handleNum} = require("../../http/http");
var url = "http://localhost:8080/top/playlist";
Page({
  data: {
    top250:[],
    total:"",
  },

  onLoad: function (options) {
    http({
      url,
      offset:0,
      limit:5,
      success:res=>this.handleHttpData(res)
    })
  },

  handleItem(event){
    var index = event.currentTarget.dataset.index;
    http({
      url,
      offset:index,
      limit:5,
      success:res=>this.handleHttpData(res)
    })
  },
  handleHttpData(res){
    var total = res.data.total;
    var top250 = [];
    res.data.data.forEach(item=>{
      console.log(item);
      var{pic,title} = item;
      top250.push({pic,title});
    })
    this.setData({
      top250,
      total:handleNum(total)
    });
  },
})